package khannedy.blogging.masterdetail.model;

import java.awt.Image;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import khannedy.blogging.masterdetail.entity.Mahasiswa;

public class TableModelMahasiswa extends AbstractTableModel {

    private List<Mahasiswa> list;

    public TableModelMahasiswa(List<Mahasiswa> list) {
        this.list = list;
    }

    public List<Mahasiswa> getList() {
        return list;
    }

    public int getRowCount() {
        return list.size();
    }

    public int getColumnCount() {
        return 6; //Edited by Jasoet
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Nim";
            case 1:
                return "Nama Depan";
            case 2:
                return "Nama Belakang";
            case 3:
                return "Tanggal Lahir";
            case 4:
                return "Jenis Kelamin";
                //Added by Jasoet [start]
            case 5:
                return "Foto";
                //Added by Jasoet [end]
            default:
                return null;
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return list.get(rowIndex).getNim();
            case 1:
                return list.get(rowIndex).getNamaDepan();
            case 2:
                return list.get(rowIndex).getNamaBelakang();
            case 3:
                return list.get(rowIndex).getTanggalLahir();
            case 4:
                return list.get(rowIndex).getJenisKelamin();
                //Added by Jasoet [start]
            case 5:
                return list.get(rowIndex).getUrlFoto();
                //Added by Jasoet [end]
            default:
                return null;
        }
    }

    //Added by Jasoet [start]
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return String.class;
            case 1:
                return String.class;
            case 2:
                return String.class;
            case 3:
                return Date.class;
            case 4:
                return Mahasiswa.JenisKelamin.class;
            case 5:
                return Image.class;
            default:
                return null;
        }
    }
    //Added by Jasoet [end]
}
